Imports System.Data
Imports System.Data.SqlClient
Imports Entidad

Public Class DocumentoAlmacenDetallePickeadorUbicacionDatos

    Sub registrarDocumentoAlmacenDetallePickeadorUbicacion(ByVal dadpu As DocumentoAlmacenDetallePickeadorUbicacion)
        Dim conex As New Conexion
        Dim coneccion As SqlConnection = conex.conectar()
        coneccion.Open()
        Dim query As String = "INSERT INTO Documento_Almacen_Detalle_Pickeador_Ubicacion(DADPU_Codigo, " & _
                              "DADP_Codigo,CIA,SUC_Codigo,ALM_Codigo,TDOC_Codigo,DCA_Codigo,ART_Codigo,UBI_Codigo, " & _
                              "DADPU_Cantidad,DADPU_CantIng,DADPU_CantPick,DADPU_FechaAsig,DADPU_FechaInicio,DADPU_FechaFin,DADPU_Activo) " & _
                              "VALUES(@dadpucod,@dadpcod,@cia,@suc,@alm,@tipodoc,@dcacod,@artcod,@ubicod, " & _
                              "@dadpucant,0,0,GETDATE(),null,null,@activo)"

        Dim comando As New SqlCommand
        With comando
            .Connection = coneccion
            .CommandText = query
            .Parameters.AddWithValue("@dadpucod", dadpu.DADPUCOD)
            .Parameters.AddWithValue("@dadpcod", dadpu.DADPCOD)
            .Parameters.AddWithValue("@cia", dadpu.CIA)
            .Parameters.AddWithValue("@suc", dadpu.SUC)
            .Parameters.AddWithValue("@alm", dadpu.ALM_Codigo)
            .Parameters.AddWithValue("@tipodoc", dadpu.TIPODOC)
            .Parameters.AddWithValue("@dcacod", dadpu.DCACOD)
            .Parameters.AddWithValue("@artcod", dadpu.ARTCOD)
            .Parameters.AddWithValue("@ubicod", dadpu.UBICOD)
            .Parameters.AddWithValue("@dadpucant", dadpu.DADPUCANT)
            .Parameters.AddWithValue("@activo", dadpu.ACTIVO)
            .ExecuteNonQuery()
        End With
        coneccion.Close()
    End Sub

    Function generarCodigoDADPU(ByVal tdocodigo As String) As Integer
        Dim conex As New Conexion
        Dim coneccion As SqlConnection = conex.conectar()
        coneccion.Open()
        Dim query As String = "SELECT COUNT(*) AS Contar FROM Documento_Almacen_Detalle_Pickeador_Ubicacion WHERE TDOC_Codigo = '" & tdocodigo & "'"

        Dim adapter As New SqlDataAdapter(query, coneccion)
        Dim ds As New DataSet
        adapter.Fill(ds)

        coneccion.Close()

        Return CInt(ds.Tables(0).Rows(0)("Contar").ToString.Trim) + 1
    End Function

End Class
